package ar.com.binarit

import org.springframework.security.core.context.SecurityContextHolder

class PersonTagLib {

	def personService
	def springSecurityService
	def facebookAuthService

	static namespace = "my"
	
	def usuarioLogueado = { attrs ->
		Person usuario = personService.usuarioLogueado
		out << "${usuario.nombre} ${usuario.apellido}"
	}
	
	def infoHeadPerson = {attrs ->
		out << g.render(template:"/templates/mainPersonMenu", model:['person':springSecurityService.currentUser, 'personDetail':null])
	}
	
	def avatarPerson = {attrs ->
		def usuario = attrs.usuario ?: springSecurityService.currentUser
		def size = "tt_avatar-person tt"
		if(attrs.size.equals('mini')){
			size += " tt_avatar-person-min"
		}
		
		if(attrs.size.equals('large')){
			size += " tt_avatar-person-large"
		}
		
		if(attrs.size.equals('xlarge')){
			size += " tt_avatar-person-xlarge"
		}
		
		if(attrs.size.equals('xmini')){
			size += " tt_avatar-person-xmin"
		}
		
		out << g.render(template:'/templates/avatarPerson', model:[usuario:usuario,'size':size, 'leyenda':attrs.leyenda])
	}
	
	def menuUsuario = { attrs ->
		if (!springSecurityService.isLoggedIn()){
			out << g.render(template:'/templates/menuLoginCreate', model:[])
//			out << g.render(template:'/perfil/crearPerfil', model:[])
		}else{
			out << g.render(template:'/templates/menuUsuario', model:[])
		}
	}
	
	def menuViajes = { attrs ->
		if (springSecurityService.isLoggedIn()){
			if (personService.usuarioLogueado.esUsuarioVerificado()){
				out << g.render(template:'/templates/menuViajes')
			}
		}
	}
	
	def tieneError = { attrs ->
		def persona = attrs.persona
		def field = attrs.field
		
		if (g.hasErrors(bean: persona, field: field)){
			return "error"
		}else{
			return ""
		}
	}
	
}
